package com.bw.lib_router

import android.content.Context
import com.alibaba.android.arouter.facade.Postcard
import com.alibaba.android.arouter.facade.annotation.Interceptor
import com.alibaba.android.arouter.facade.callback.InterceptorCallback
import com.alibaba.android.arouter.facade.template.IInterceptor
import com.tencent.mmkv.MMKV

/**
 *Router路由拦截器
 */

@Interceptor(priority = 5, name = "路由参数拦截器")
class RouterParamsInterceptor :IInterceptor{
    private lateinit var mContext:Context

    override fun init(context: Context?) {
        if (context!=null){
            mContext=context
        }
    }

    override fun process(postcard: Postcard, callback: InterceptorCallback) {
        val accessId = MMKV.defaultMMKV().decodeString("accessId", "park_default_access_id")
        if (!accessId.isNullOrEmpty()){
            postcard.withString("accessId",accessId)//携带参数
        }
        callback.onContinue(postcard)

    }
}